15.1 Fundamental Concepts
After executing the exception handler initialization, start_kernel() invokes the mm_init() function to allocate memory for several buffers utilized by memory management and to initialize the associated variables and structures. To better comprehend the memory initialization procedure, this section first introduces the fundamental concepts utilized in memory management, memory allocation algorithms, page extensions (page_ext), and bounce buffer technologies. Following this, it outlines the execution process of mm_init() and the basic functionalities of the functions it invokes.
Across the preceding chapters, we have progressively introduced concepts used in memory management, such as Non-Uniform Memory Access (NUMA), nodes, memory zones, page migration, and memory compaction. Furthermore, memory management encompasses concepts including huge pages, compound pages, and memory reclamation.
Currently, mainstream computer architectures utilize 4096 bytes as a standard page and execute memory allocation via the Translation Lookaside Buffer (TLB) cache. However, with the evolution of computer architectures, many computer systems have surpassed the 4 GiB address space barrier. Under these circumstances, if 4096 bytes is stubbornly maintained as the page size, the cache hit rate will degrade. To mitigate this issue, many computer architectures have adopted memory management hardware with larger page dimensions. The page sizes adopted by this hardware can reach 2 MiB or even 1 GiB. Linux designates pages larger than 4 KiB as huge pages.
A compound page is a collection of multiple contiguous memory pages utilized to describe a SLAB allocation that is larger than a single physical memory page. The first memory page therein is designated as the head page of the compound page, while the remaining pages act as tail pages. The head page is flagged within the flags field of its page structure; when the PG_head bit (bit 16) of flags evaluates to 1, it indicates that this memory page represents the head page of a compound page. A tail page is identified by the least significant bit of the compound_head field within its page structure, where a value of 1 signifies that the page is a tail page. The remaining bits of compound_head preserve the base memory address of the head page belonging to the compound page hosting that tail page. The first tail page is unique, as it preserves supplemental metadata including the order of the compound page, the total number of memory pages enclosed within the compound page, and the associated destructor function.
Throughout different phases of system runtime operation, a single page of physical memory can be utilized to store distinct categories of data. Much of this data either has an existing backup in an external storage space like a hard disk drive, or can be paged out into an external swap area. Memory pages preserving this specific category of data are classified as reclaimable memory pages, and the physical space occupied by reclaimable memory pages can be safely released. The operation of releasing reclaimable memory pages is designated as memory page reclamation.